<template>
  <div class="app-container table-app-container">
    <div class="fixed-table">
      <PageableTable
        :loading="loading"
        :data="insideTableData"
        :total="totalElements"
        :page="currentPage"
        :page-size="pageSize"
        :table-height="tableHeight"
        class="fixed-table-table"
        @page-change="onPageChange"
        @sort-change="onSortChange"
      >
        <el-table-column v-for="column in insideColumns" :key="column.key" :label="column.title" :prop="column.key" :sortable="column.sortable">
          <template slot-scope="scope">
            <column-render :render="column.render" :row="scope.row" :column="column" />
          </template>
        </el-table-column>
      </PageableTable>
    </div>
  </div>
</template>

<script>
import PageableTable from '@neu/biz-core/components/PageableTable'
import databind from '@neu/biz-core/mixins/databind'
import { formatDate, on } from '@neu/biz-core/utils/utils'
import { debounce } from '@neu/biz-core/utils'

import {
  page,
  remove
} from '@neu/dcam-ui/api/storehouseRecord'
export default {
  name: 'StorehousePage',
  components: {
    PageableTable
  },
  // 加入混入，使表格混入更多的api操作
  mixins: [databind],
  props: {
    forSelection: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      r: page,
      d: remove,
      insideColumns: [
        { title: '分类', key: 'type',
          render: (h, params) => { return h('span', params.row.type === '1' ? '入库' : '出库') }
        },
        { title: '时间', key: 'createTime', render: (h, params) => { return h('span', formatDate(params.row.createTime, 'YYYY-MM-DD HH:mm')) } },
        { title: '名称', key: 'name' },
        { title: '类型', key: 'smallTypeName' },
        { title: '规格型号', key: 'specifications' },
        { title: '数量', key: 'amount' }
      ]
    }
  },
  created() {
    const obj = { 's_location': this.$attrs.location }
    this.filter(obj)
  },
  methods: {
    // 自适应页面高度
    initListener() {
      this.$_resizeHandler = debounce(() => {
        const _this = this
        _this.tableHeight = window.innerHeight * 0.9 - 180
      }, 100)

      on(window, 'resize', this.$_resizeHandler)
    }
  }
}
</script>
